home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / stuffky.exe / KEYBOARD.C < prev    next >
Text File  |  1991-07-17  |  2KB  |  60 lines

  1. /* KEYBOARD.C
  2. This file contains an assortment of Keyboard handling rutines. None
  3. of the rutines are ment to be executed independently- rather they
  4. are ment to be linked with and called from a program of your own.
  5. For more information on keyboard buffer handling in the IBM PC, please
  6. read the comments in the file STUFFKB3.ASM. For more programming examples
  7. in both C and ASM, please see STUFFKB3.ASM.
  8.  
  9. Note: All examples below were writen for compilation with Turbo C ver. 2.01
  10. (By Borland International). 
  11.  
  12. The information contained may be considered Public Domain and may be used
  13. freely as long as the author is not held libiable for its soundness.
  14. */
  15.  
  16. /*Note: The below examples assume that the keyboard buffer has been setup
  17. in the way that a IBM computer would by default. It has been left up to
  18. you to determin, if necessary, whether this default condition still exists.*/
  19.  
  20.  
  21. #include <dos.h>
  22.  
  23. int anykeys(void);    /*checks for presence of keystorkes in buffer. returns
  24.                      1 if present, 0 if not. Not confused by <cntrl><brks>*/
  25. void clrkb(void);    /*clears keyboard buffer by setting head=tail. */
  26.  
  27.  
  28.  
  29. int anykeys(void)
  30. {
  31. /*return 0 if 0 keys in buffer, else return 1. Keyboard buffer not otherwise
  32. affected.*/
  33.  
  34. int far *head;
  35. int far *tail;
  36.  
  37. head=          MK_FP(0x40,0x1A);
  38. tail=          MK_FP(0x40,0x1C);
  39.  
  40. if (*head==*tail)
  41.     return(0);
  42.   else
  43.     return(1);
  44. }
  45.  
  46.  
  47. void clrkb(void)
  48. {
  49. /*quickly clears the keyboard buffer */
  50. int far *head;
  51. int far *tail;
  52.  
  53. head=          MK_FP(0x40,0x1A);
  54. tail=          MK_FP(0x40,0x1C);
  55.  
  56. *head=*tail;
  57. }
  58.  
  59.  
  60.